package com.android.kuai.zhuan.activity;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.kuai.zhuan.R;
import com.android.kuai.zhuan.utils.CommonUtils;
import com.android.kuai.zhuan.utils.QrCodeHandler;

public class AboutUsActivity extends AppCompatActivity {

    ImageView ivBarCode;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_us);

        setToolbar();
        ivBarCode = findViewById(R.id.iv_code_bar);
        String imei = CommonUtils.getPhoneImei();
        if(!TextUtils.isEmpty(imei)) {
            createBarCode(imei);
        }
    }

    private void setToolbar() {
        Toolbar toolbar = findViewById(R.id.my_toolbar);
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(R.mipmap.toolbar_back);
        TextView toolbarTitle = findViewById(R.id.toolbar_title);
        toolbarTitle.setText("关注我们");
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private Bitmap createBarCode(String key) {
        Bitmap qrCode = null;
        try {
            qrCode = QrCodeHandler.createBarCode(key, 900, 180);
            ivBarCode.setImageBitmap(qrCode);
        } catch (Exception e) {
            Toast.makeText(this,"输入的内容条形码不支持！",Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
        return qrCode;
    }
}
